$(document).ready(function(){
	var contextPath = document.location.pathname;
	var index = contextPath.substr(1).indexOf("/");
	contextPath = contextPath.substr(1, index);
	var basePath = "/" + contextPath;
	initProvince();
	var province = null;
	var city = null;
	var area = null;
	
	var validObject = $("#personalInfo").Validform({
		
		dataType:'json',
		tiptype:2,
		ajaxPost:true,
		
		callback:function(data){
			var memberId = data.memberId;
			window.location.assign(basePath+"/HRTWEB/jumpToPass.do?memberId="+memberId);
			
		},
		
		tiptype:function(msg,o,cssctl){
			
			if(!o.obj.is("form")){
				var tds=o.obj.text();
				
				var objtip=o.obj.siblings(".Validform_checktip");
				cssctl(objtip,o.type);
				objtip.text(msg);
			
				
			}	
			
		}
	
	});
	
	$("#personalInfo").delegate('#mail', 'blur', function() {
		validObject.config({
		 ajaxurl:{
		        success:function(data,obj){
		        	if(data.status=="y"){
		        		$("#getEmail").removeAttr("disabled");
		        		
		        	}
		        	else{
		        		$("#getEmail").attr("disabled","disabled");
		        	}
		           
		        },
		    	 error:function(data,obj){
			            alert("error:"+data+obj);
			        }
		        
		    }
			
			
		});
	});
	
	$("#personalInfo").delegate('#getEmail', 'click', function() {
		var mail = $("#mail").val();
		alert("mail------------->"+mail);
		var activeUrl = basePath+"/HRTWEB/activeMail.do";
		$.ajax({
			type:"POST",
			url : activeUrl,
			dataType : 'text',
			cache : false,
			data : {
				mail : mail
			},
			success : function(data) {
				alert(data);
			},
			error : function(html) {
				alert("Load Data failly");
			}
		});
	});
	
	/**
	 * 初始化省份
	 */
	function initProvince(){
		 var seachprov = $("#seachprov");
			var editUrl = basePath+"/HRTWEB/address/province/list.do";
			$.ajax({

				url : editUrl,
				dataType : 'json',
				cache : false,

				success : function(data) {
					var results = data.provinceList;
					
					var rowContent = "<option  value ='-1' >请选择</option>";
					if(results!=null){
						
						for(i=0;i<results.length;i++){
							var province =results[i];
							rowContent = rowContent+"<option  value ="+province.code+" >"+province.name+"</option>";
						}
					}
					seachprov.append(rowContent);
				},
				error : function(html) {
					alert("Load Data failly");
					refresh();
				}
			});
	}
	
});

function changeComplexProvince(provincecode) {
	$("#seachcity").empty(); //改变省份时先清空原先的市
	$("#seachdistrict").empty();
	var seachcity = $("#seachcity");
	province = $("#seachprov option:selected").text();
	
	var editUrl ="/HRTWeb3/HRTWEB/address/city/list.do?";
	$.ajax({

		url : editUrl,
		dataType : 'json',
		cache : false,
		data : {
			provincecode : provincecode
		},
		success : function(data) {
			var results = data.cityList;
			
			var rowContent = "<option  value ='-1' >请选择</option>";
			if(results!=null){
				
				for(i=0;i<results.length;i++){
					var city =results[i];
					rowContent = rowContent+"<option  value ="+city.code+" >"+city.name+"</option>";
				}
			}
			seachcity.append(rowContent);
		},
		error : function(html) {
			alert("Load Data failly");
			refresh();
		}
	});


}
function pickDate(){
	laydate({
        elem: '#myborth',
        format: 'YYYY-MM-DD',
        festival: true, //显示节日
    });
}

function changeCity(citycode) {
$("#seachdistrict").empty(); //改变城市时先删除原先的区
var seachdistrict = $("#seachdistrict");

city = $("#seachcity option:selected").text();


var editUrl ="/HRTWeb3/HRTWEB/address/area/list.do?";
$.ajax({

	url : editUrl,
	dataType : 'json',
	cache : false,
	data : {
		citycode : citycode
	},
	success : function(data) {
		var results = data.areaList;
		
		var rowContent = "<option  value ='-1' >请选择</option>";
		if(results!=null){
			
			for(i=0;i<results.length;i++){
				var area =results[i];
				rowContent = rowContent+"<option  value ="+area.code+" >"+area.name+"</option>";
			}
		}
		seachdistrict.append(rowContent);
	},
	error : function(html) {
		alert("Load Data failly");
		refresh();
	}
});

}
function changeArea(areacode){
area = $("#seachdistrict option:selected").text();

var address = province+city+area;

$("#address").val(address);

}

function clearAddress() {
$("#seachprov").empty(); 
$("#seachcity").empty(); 
$("#seachdistrict").empty(); 
}




